from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time

# 初始化Edge浏览器
driver = webdriver.Edge()

try:
    # 打开网易云课堂登录页面
    driver.get("https://study.163.com/member/login.htm")

    # 点击"邮箱登录"选项
    email_login_button = driver.find_element(By.XPATH, '//a[@class="email-login"]')
    email_login_button.click()

    # 等待页面加载
    time.sleep(10)

    # 在账号输入框中输入邮箱账号
    email_input = driver.find_element(By.NAME, "email")
    email_input.send_keys("test001@126.com")

    # 在密码输入框中输入密码
    password_input = driver.find_element(By.NAME, "password")
    password_input.send_keys("test12345")

    # 点击取消勾选 "十天内免登录" 选型
    remember_me_checkbox = driver.find_element(By.CLASS_NAME, "remember-me")
    if remember_me_checkbox.is_selected():
        remember_me_checkbox.click()

    # 点击登录按钮
    login_button = driver.find_element(By.ID, "dologin")
    login_button.click()

    # 等待一段时间以观察结果
    time.sleep(20)
finally:
    # 关闭浏览器
    driver.quit()
